#!/usr/bin/perl
#
# Little command-line tool to go from http -> sgn.
#
# $ ./sgnodemapper http://twitter.com/bradfitz
# sgn://twitter.com/?ident=bradfitz
#

use strict;
use FindBin;
use lib 'embedding/perl/lib';
use SocialGraph::NodeMapper;

my $arg = shift;
unless ($arg && $arg =~ /^http/) {
  die "Usage: sgnodemapper <http_url>\n";
}

my $js_file = "$FindBin::Bin/nodemapper.js";
unless (-e $js_file) {
  die "Can't find nodemapper.js at $js_file\n";
}

my $mapper = SocialGraph::NodeMapper->new($js_file);
my $out = $mapper->graph_node_from_url($arg);

if ($out =~ /^sgn:/) {
  print "$out\n";
} else {
  print STDERR "# $out\n";
}


